﻿using System;
using System.Linq.Expressions;

namespace CodeMinder.Core
{
    public static class Assure
    {
        public static void ThatArgument<T>(Expression<Func<T>> parameter, Expression<Func<T, bool>> isValid)
        {
            var message = string.Format("Argument {0} did not comply to condition {1}", parameter.Body, isValid.Body);

            ThatArgument(parameter, isValid, message);
        }

        public static void ThatArgument<T>(Expression<Func<T>> parameter, Expression<Func<T, bool>> isValid, string message)
        {
            if (!isValid.Compile().Invoke(parameter.Compile().Invoke()))
                throw new ArgumentException(message);
        }
    }
}